package br.com.zeneplayer.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JTextField;

import br.com.zeneplayer.controller.MusicEngine;



public class IPlayList
extends JTextField
implements ActionListener
{
	private static final long	serialVersionUID	= 9082051469980848841L;
	
	MusicEngine musicEngine;

	public IPlayList(MusicEngine engine)
	{
		this.musicEngine = engine;
		
		this.addActionListener(this);
	}

	public IPlayList(int i, MusicEngine engine)
	{
		super(i);
		
		this.musicEngine = engine;	

		this.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		String frase = ((JTextField) (e.getSource())).getText();

		if (!frase.equals(""))
		{
			String[] palavras = frase.split(" ");

			boolean useCriteria = true;
			
			if (palavras.length > 1)
			{
				musicEngine.analisarFrase(palavras);

				musicEngine.loadMusics(useCriteria);
			}
		}
	}
}
